/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package boole.application.vue;

import boole.port._Port;
import java.awt.Color;

/**
 *
 * @author Rémi PIOTAIX <remi.piotaix@gmail.com>
 */
public class VuePort extends javax.swing.JPanel {

    private _Port port;

    /**
     * Creates new form VuePort
     */
    public VuePort(int i, _Port p) {
        this.port = p;
        initComponents();
        this.labelText.setText(Integer.toString(i));
    }

    @Override
    public void repaint() {
        Color c;
        if (port == null) {
            return;
        }

        if (port.getValeur()) {
            c = new Color(0, 255, 0);
        } else {
            c = new Color(255, 0, 0);
        }
        this.setBackground(c);
        super.repaint();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelText = new javax.swing.JLabel();

        labelText.setText("i");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(labelText, javax.swing.GroupLayout.DEFAULT_SIZE, 18, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(labelText)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel labelText;
    // End of variables declaration//GEN-END:variables

    public void update() {
        repaint();
    }
}
